﻿<% @ LANGUAGE="VBSCRIPT" CODEPAGE="65001" %>
<% Option Explicit %>

<!-- #include file="../adovbs.inc" -->
<!-- #include file="checkfile.asp" -->

<%
    Dim id
    Dim path, filename
    Dim checkMsg

    id = Request.QueryString("code")

    checkMsg = checkfile(id)
    
    If checkMsg Then
        path = Server.MapPath("/") & "\..\database\images\"
        filename = path & Replace(id,".","") & ".pc"
        Response.Expires = 0
        Response.Buffer = TRUE
        Response.Clear
        Response.ContentType = "image/jpeg"
        DecryptImage(filename)
        Response.Flush
    Else
        Response.Write("FILE_NOT_FOUND")
    End If

    Function DecryptImage(filename)
      Dim i, size
      Dim BinaryStream

      Const adTypeBinary = 1
  
      'Create Stream object
      Set BinaryStream = CreateObject("ADODB.Stream")
  
      'Specify stream type - we want To get binary data.
      BinaryStream.Type = adTypeBinary
  
      'Open the stream
      BinaryStream.Open
  
      'Load the file data from disk To stream object
      BinaryStream.LoadFromFile fileName

      size = BinaryStream.Size
      BinaryStream.Position = size-20
      Response.BinaryWrite BinaryStream.Read(20)

      BinaryStream.Position = 20

      For i=21 To size-20   
        Response.BinaryWrite BinaryStream.Read(1)
      Next

      BinaryStream.Position = 0
      Response.BinaryWrite BinaryStream.Read(20)

      BinaryStream.Close
  
      Set BinaryStream = Nothing
    End Function
%>
